package org.jsola.contract.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.jsola.contract.dto.SignWeiXinSendDTO;
import org.jsola.contract.entity.AppendixDO;
import org.jsola.contract.entity.ContractDO;
import org.jsola.contract.service.IContractSignCallbackService;
import org.jsola.contract.vo.PartySignAccountVO;
import org.jsola.user.core.TokenUser;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author JanusMix
 */
@Service("defaultContractSignCallbackServiceImpl")
@Slf4j
public class DefaultContractSignCallbackServiceImpl implements IContractSignCallbackService {


    @Override
    public void onPublish(ContractDO contractDO, List<PartySignAccountVO> partySignAccountList, AppendixDO appendixDO, TokenUser tokenUser) {
        LoggerFactory.getLogger(IContractSignCallbackService.class).info("【" + contractDO.getName() + "】发起签署成功");
    }

    @Override
    public void onSuccess(ContractDO contractDO, List<PartySignAccountVO> partySignAccountList, AppendixDO appendixDO, TokenUser tokenUser) {
        LoggerFactory.getLogger(IContractSignCallbackService.class).info("【" + contractDO.getName() + "】签署成功");
    }

    @Override
    public void onComplete(ContractDO contractDO, List<PartySignAccountVO> partySignAccountList, AppendixDO appendixDO, TokenUser tokenUser) {
        LoggerFactory.getLogger(IContractSignCallbackService.class).info("【" + contractDO.getName() + "】签署完成");
    }

    @Override
    public void onExpired(List<ContractDO> contractList) {
        LoggerFactory.getLogger(IContractSignCallbackService.class).info("【"
                + contractList.parallelStream().map(ContractDO::getName).collect(Collectors.joining(",")) + "】已过期");
    }

    @Override
    public void onFailed(ContractDO contractDO, String message, TokenUser tokenUser) {
        LoggerFactory.getLogger(IContractSignCallbackService.class).info("【" + contractDO.getName() + "】签署失败，原因:" + message);
    }

    @Override
    public void sendMessage(List<SignWeiXinSendDTO> sendList,String subjectName, TokenUser tokenUser) {
        LoggerFactory.getLogger(IContractSignCallbackService.class).info("发送信息完成");
    }
}
